#!/bin/bash
#
# Prints statistics from a dovado tiny, for example on login
# (w) Bjorn Rohlen (c) 2012
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#


dovado_tiny_ip="192.168.191.2"
stat_file="cgi-bin/statusbar.data.cgi?getall"
url="http://${dovado_tiny_ip}/${stat_file}"
content=$(wget -qO- $url)

sigstre=$(echo $content | sed "s/.*signalstrength:'\(.*\) % (.*/\1%/")
wanstat=$(echo $content | sed "s/.*wanstatus:'\([^']*\).*/\1/")
dlgig=$(echo $content | sed "s/.*rx_this:'\([^']*\).*/\1/")
ulgig=$(echo $content | sed "s/.*tx_this:'\([^']*\).*/\1/")
wanip=$(echo $content | sed "s/.*wan_ip:'\([^']*\).*/\1/")

if [ $wanstat == "DISCONNECTED" ]; then
echo -ne \
"WAN Status: $wanstat \
| Downloaded: ${dlgig}Gb \
| Uploaded: ${ulgig}Gb \
\n\n"
else
echo -ne \
"WAN Status: $wanstat \
| Downloaded: ${dlgig}Gb \
| Uploaded: ${ulgig}Gb \
| Signal Strength: $sigstre \
| WAN IP: ${wanip} \
\n\n"
fi
